<template>
    <div>
        <breadcrumb :routerList="routerList"></breadcrumb>
        <el-button type="primary" icon="el-icon-plus" @click="newClassClick">新增banner</el-button>
        <bannerTable :bannerList="bannerList" @refreshTableFun="refreshTableFun"></bannerTable>
    </div>
</template>

<script>
import breadcrumb from '@/components/breadcrumb.vue'
import bannerTable from '@/components/bannerTable.vue'

export default {
    components: {breadcrumb,bannerTable},
    data(){
        return {
            routerList: [
                {
                    name: 'banner列表',
                    path: ''
                },
            ],
            bannerList: [],
            shopList:[],
            productsList:[]
        }
    },
    created(){
        this.getProducts();
        this.getSupplierList();
    },
    mounted(){
        setTimeout(()=>{
            this.getBanner();
        },100)
    },
    methods:{
        async getBanner(){
            let res = await this.$Http.getBannerList()
            if(res.length!=0){
                for(let i in res){
                    let type = res[i].type;
                    if(type == 1){
                        for(let j in this.productsList){
                            console.log(res[i].fid);
                            if(res[i].fid == this.productsList[j].id){
                                console.log(this.productsList[j].product_name);
                                res[i].link_name = this.productsList[j].product_name
                            }
                        }
                    }
                    if(type == 2){
                        for(let j in this.shopList){
                            if(res[i].fid == this.shopList[j].id){
                                res[i].link_name = this.shopList[j].supplier_name
                            }
                        }
                    }
                }
                // console.log(res);
                this.bannerList = res
                // console.log(this.bannerList)
            }
        },
        newClassClick(){
            this.$router.push({
                path: '/newBanner',
                query: {type: 1,list: ''}
            })
        },
        refreshTableFun(){
            this.getBanner()
        },
        async getProducts(){
            let res = await this.$Http.getGoodsList({
                tj:10,
                status:1
            })
            // console.log(res);
            this.productsList = res;
        },
        async getSupplierList(){
            let res = await this.$Http.getSupplier()
            // console.log(res)
            this.shopList = res.list;
        },
    }
}
</script>

<style>
    .el-button{
        margin: 20px 0;
    }
</style>
